package com.java.learning.demo.controller;

import com.java.learning.demo.common.ResultData;
import com.java.learning.demo.entity.Student;
import com.java.learning.demo.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@AllArgsConstructor
@RestController
@Api(tags = "学生API")
@Slf4j
public class StudentController {
    private StudentService studentService;

    @PostMapping("/student/register")
    @ApiOperation("学生注册")
    @Validated
    public ResultData<String> register(@RequestBody @Validated Student student) {
        studentService.saveStudent(student);
        return ResultData.SUCCESS;
    }

    @GetMapping("/student/getOne")
    @ApiOperation("查询一个学生")
    public ResultData<Student> getStudent(@RequestParam("stuNo") String stuNo){
        Student student=studentService.getStudent(stuNo);
        return ResultData.newInstance(student);
    }

}
